package com.easy.tool.utils.array;

import com.easy.tool.anno.BeanDes;
import com.easy.tool.anno.MethodDes;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 高俊
 * @create 2022-01-2022/1/9-19:04
 */
@BeanDes(name = "集合工具类",des = "可以实现集合的常用简单操作")
public class ArrayUtils<T> {
    /**
     * 判断list集合是否为空
     * @param list
     * @param <T>
     * @return
     */
    @MethodDes(des = "判断list集合是否为空",param = {"arg0 -> list：list集合"})
    public static <T> List<T> CollectionEmpty(List<T> list){
        if (list == null){
            return new ArrayList<>();
        }
        return list;
    }

    /**
     * 判断list集合长度是否为0
     * @param list
     * @return
     * @param <T>
     */
    @MethodDes(des = "判断list集合长度是否为0",param = {"arg0 -> list：list集合"})
    public static <T> boolean CollectionBlank(List<T> list){
        if(list != null){
            if (list.size() == 0){
                return Boolean.TRUE;
            }
            return Boolean.FALSE;
        }
        return Boolean.FALSE;
    }

    /**
     * 倒序输出list集合
     * @param list
     * @param <T>
     * @return
     */
    @MethodDes(des = "倒序输出list集合",param = {"arg0 -> list：list集合"})
    public static <T> List<T> reversed(List<T> list){
        List<T> result = new ArrayList<>();
        for (int i = list.size()-1; i >= 0 ; i--) {
            result.add(list.get(i));
        }
        return result;
    }

    /**
     * 多参数传递创建list集合
     * @param objects
     * @return
     */
    @MethodDes(des = "多参数传递创建list集合",param = {"arg0 -> objects：多个objects参数"})
    public static List<Object> create(Object... objects){
        List<Object> list = new ArrayList<>(10);
        for (Object n : objects) {
            list.add(n);
        }
        return list;
    }
}
